package com.wswy.wzcx.ui.component

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.che.libcommon.api.BaseResult
import com.che.libcommon.api.ProgressDialogObserver
import com.wswy.wzcx.R
import com.wswy.wzcx.api.Api
import com.wswy.wzcx.model.MyOrderMode
import com.wswy.wzcx.ui.activity.UpLoadActivity
import com.wswy.wzcx.ui.data.OrderNoNeedParam

/**
 * Created by wangduheng26 on 2018/4/3.
 * wangduheng26@gmail.com
 */
class MyOrderComponent(parent: ViewGroup) : DataBindingComponent<MyOrderMode>(parent, R.layout.item_my_order2) {
    private val ivIcon: ImageView = view.findViewById(R.id.iv_icon)
    private val viewd: View = view.findViewById(R.id.divider)
    private val tvTitle : TextView = view.findViewById(R.id.tv_title)
    private val tvDate : TextView = view.findViewById(R.id.tv_date);
    private val tvStatus : TextView = view.findViewById(R.id.tv_status)

    val tvName: View = view.findViewById(R.id.tv_name)
    val tvUpload: View = view.findViewById(R.id.tv_upload)
    override fun bind(data: MyOrderMode?) {
        super.bind(data)

        tvTitle.text = data?.title
        tvDate.text = data?.updateTime
        tvStatus.text = data?.statusName

        ivIcon.setImageResource(data?.getIcon()?:0)
//        tvName.visibility = if (data.getNeedUpload()) View.INVISIBLE else View.INVISIBLE
        tvUpload.visibility = if (data?.getNeedUpload() == true) View.VISIBLE else View.GONE
        tvUpload.setOnClickListener {
//            Api.get().fetchOrderNeedParams(data?.orderNo)
//                    .subscribe(object :ProgressDialogObserver<List<OrderNoNeedParam>>(tvUpload.context){
//                        override fun onApiResult(t: List<OrderNoNeedParam>?) {
//                            UpLoadActivity.startUploadPage(tvUpload.context,data?.orderNo,t?.toTypedArray())
//                        }
//
//                        override fun onApiError(result: BaseResult<*>?) {
//                            toastErrorMsg(result)
//                        }
//
//                    })
        }

    }
}